"""
Pytest configuration and fixtures.
"""

import json
from pathlib import Path

import pytest
from orchestrator.ir.nodes import ClassDeclaration


@pytest.fixture
def test_data_dir() -> Path:
    """Get the test data directory path"""
    return Path(__file__).parent / "test_data"


@pytest.fixture
def sample_roslyn_json(test_data_dir: Path) -> str:
    """Load sample Roslyn JSON output"""
    json_file = test_data_dir / "sample_roslyn_output.json"
    return json_file.read_text(encoding="utf-8")


@pytest.fixture
def sample_roslyn_dict(sample_roslyn_json: str) -> dict:
    """Load sample Roslyn JSON as dictionary"""
    return json.loads(sample_roslyn_json)


@pytest.fixture
def sample_person_json(test_data_dir: Path) -> str:
    """Load sample Person JSON output"""
    json_file = test_data_dir / "sample_person_output.json"
    return json_file.read_text(encoding="utf-8")


@pytest.fixture
def sample_class_ir(sample_roslyn_dict: dict) -> ClassDeclaration:
    """Create a sample ClassDeclaration IR from Roslyn JSON"""
    from orchestrator.ir.builder import IRBuilder

    builder = IRBuilder()
    classes = builder.build_from_json(sample_roslyn_dict)
    return classes[0] if classes else None  # type: ignore
